package com.winterwar.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.winterwar.base.Table;
import com.winterwar.dao.TableDAO;

public class TableDAOHibernate extends HibernateDaoSupport implements TableDAO {

	private Log log = LogFactory.getLog(TableDAO.class);
	
	public Table get(Integer tableID) {
		return (Table) getHibernateTemplate().get(Table.class, tableID);
	}

	public List getAll() {
		return (List) getHibernateTemplate().find("from Table order by physicalTables asc");
	}

	public void remove(Integer tableID) {
		Object table = getHibernateTemplate().load(Table.class, tableID);
		getHibernateTemplate().delete(table);
	}

	public void save(Table table) {
		getHibernateTemplate().saveOrUpdate(table);
		if (log.isDebugEnabled()) {
			log.debug("userId set to: " + table.getTableID());
		}	
	}

	public List getByConID(Integer conID) {
		return getHibernateTemplate().find("from Table where conID = " + conID.intValue() + " order by tableName");
	}

}
